package cn.superchart.module.menu.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.superchart.common.base.BaseController;
import cn.superchart.common.base.BaseResult;
import cn.superchart.module.menu.param.*;
import cn.superchart.module.menu.service.ScMenuService;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Validated
public class ScMenuController extends BaseController<ScMenuService> {

    @PostMapping("/sc/menu/add")
    public BaseResult<String> add(@RequestBody @Valid ScMenuAddParam scMenuAddParam) {
        service.add(scMenuAddParam);
        return BaseResult.ok();
    }

    @PostMapping("/sc/menu/edit")
    public BaseResult<String> edit(@RequestBody @Valid ScMenuEditParam scMenuEditParam) {
        service.edit(scMenuEditParam);
        return BaseResult.ok();
    }

    @DeleteMapping("/sc/menu/delete")
    public BaseResult<String> delete( @Valid ScMenuIdParam scMenuIdParam) {
        service.delete(scMenuIdParam.getId());
        return BaseResult.ok();
    }

    @GetMapping("/sc/menu/detail")
    public BaseResult<ScMenuDetailParam> detail(@Valid ScMenuIdParam scMenuIdParam) {
        return BaseResult.result(service.detail(scMenuIdParam.getId()));
    }

    @GetMapping("/sc/menu/menuTrees")
    public BaseResult<List<Tree<String>>> menuTrees() {
        return BaseResult.result(service.menuTrees());
    }

    @GetMapping("/sc/menu/getMenus")
    public BaseResult<ScMenuData> getMenus() {
        return BaseResult.result(service.getMenus());
    }


    @PostMapping(value="/sc/menu/downMenuTs")
    public void downMenuTs(){
        service.downMenuTs();
    }


    @GetMapping("/sc/menu/menuTreeForAssign")
    public BaseResult<ScMenuTreeData> menuTreeForAssign() {
        return BaseResult.result(service.menuTreeForAssign(getUserId()));
    }
}
